package com.patrol.patrol.ui.route;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.patrol.patrol.R;

import java.util.List;

public class RouteAdapter extends RecyclerView.Adapter<RouteAdapter.RouteViewHolder> {

    Context context;
    List<Route> routes;
    NestRouteAdapter nestRouteAdapter;

    public RouteAdapter(Context context, List<Route> routes) {
        this.context = context;
        this.routes = routes;

        nestRouteAdapter = new NestRouteAdapter(routes,context);
    }


    public void notifyDataChange(){
        nestRouteAdapter.notifyDataSetChanged();
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RouteViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_route, parent, false);
        return new RouteViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RouteViewHolder holder, int position) {
        nestRouteAdapter.setCurrentPosition(position);
        holder.rcy_detail_item.setAdapter(nestRouteAdapter);

        holder.tv_title.setText(routes.get(position).getFirstTitle());
    }


    @Override
    public int getItemCount() {
        return routes.size();
    }

    class RouteViewHolder extends RecyclerView.ViewHolder{

        TextView tv_title;
        RecyclerView rcy_detail_item;

        public RouteViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_title);
            rcy_detail_item = itemView.findViewById(R.id.rcy_detail_item);

            rcy_detail_item.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL,false));
        }
    }

}
